package com.jingzhongbao.springboot.controller;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jingzhongbao.springboot.dao.UserRepository;
import com.jingzhongbao.springboot.domain.User;

@RestController
public class TestController {
	@Autowired
	private UserRepository userRepository;
	
	@RequestMapping("/index")
	public String index() {
		return "Hello World!";
	}
	@RequestMapping("/save")
	public void save() {
		User user = new User();
		userRepository.save(user);
	}
	
	@RequestMapping("/getUser")
	public User getUser() {
		return userRepository.findByUsername("关羽");
	}
	
	@RequestMapping("/delete")
	public void delete() {
		Optional<User> optional = userRepository.findById("1");
		userRepository.delete(optional.get());
	}
	@RequestMapping("/update")
	public int  update() {
		return userRepository.modifyByIdAndUserId("关羽", "1");
	}
}
